﻿//-----------MsAccess.cs
//--------------------------
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.OleDb;

namespace DataAccess
{
    public class MsAccess
    {
        private static string _connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=QLHS.mdb";
        //Provider=Microsoft.ACE.OLEDB.12.0;Data Source=
        public static String ConnectionString
        {
            get
            {
                return _connectionString;
            }
            set
            {
                _connectionString = value;
            }
        }
        public static DataTable ExecuteQuery(string sql)
        {
            OleDbConnection cn = new OleDbConnection(ConnectionString);

            OleDbCommand cmd = new OleDbCommand();
            cmd.Connection = cn;
            cmd.CommandText = sql;

            OleDbDataAdapter adp = new OleDbDataAdapter(cmd);
            DataTable kq = new DataTable();
            adp.Fill(kq);
            cn.Close();
            return kq;
        }
        public static void ExecuteNonQuery(string sql)
        {
            OleDbConnection cn = new OleDbConnection(ConnectionString);

            OleDbCommand cmd = new OleDbCommand();
            cmd.Connection = cn;
            cmd.CommandText = sql;
            
            cn.Open();
            cmd.ExecuteNonQuery();
            cn.Close();
        }
    }
}
